﻿Imports System.Windows.Forms
Imports System.Data.SqlClient

Public Class Accueil

    Private user As String
    Private userSite As String
    Private profil As String
    Private cn As CnData
    Private da As SqlDataAdapter
    Private ds As DataSet
    Private cmd As SqlCommand
    Private dtr As SqlDataReader
    Private WithEvents c As SqlConnection


    Private Sub ShowNewForm(ByVal sender As Object, ByVal e As EventArgs)
        ' Créez une nouvelle instance du formulaire enfant.
        Dim ChildForm As New System.Windows.Forms.Form
        ' Configurez-la en tant qu'enfant de ce formulaire MDI avant de l'afficher.
        ChildForm.MdiParent = Me

        m_ChildFormNumber += 1
        ChildForm.Text = "Fenêtre " & m_ChildFormNumber

        ChildForm.Show()
    End Sub

    Public Sub DeclareUser(ByVal user As String, ByVal userSite As String, ByVal profil As String)
        Me.user = user
        Me.userSite = userSite
        Me.profil = profil
    End Sub

    Private Sub OpenFile(ByVal sender As Object, ByVal e As EventArgs)
        Dim OpenFileDialog As New OpenFileDialog
        OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        OpenFileDialog.Filter = "Fichiers texte (*.txt)|*.txt|Tous les fichiers (*.*)|*.*"
        If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            Dim FileName As String = OpenFileDialog.FileName
            ' TODO: ajoutez le code ici pour ouvrir le fichier.
        End If
    End Sub

    Private Sub SaveAsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim SaveFileDialog As New SaveFileDialog
        SaveFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments
        SaveFileDialog.Filter = "Fichiers texte (*.txt)|*.txt|Tous les fichiers (*.*)|*.*"

        If (SaveFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then
            Dim FileName As String = SaveFileDialog.FileName
            ' TODO: ajoutez le code ici pour enregistrer le contenu actuel du formulaire dans un fichier.
        End If
    End Sub


    Private Sub ExitToolsStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles ExitToolStripMenuItem.Click
        Me.Close()
    End Sub

    Private Sub CutToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        ' Utilisez My.Computer.Clipboard pour insérer les images ou le texte sélectionné dans le Presse-papiers
    End Sub

    Private Sub CopyToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        ' Utilisez My.Computer.Clipboard pour insérer les images ou le texte sélectionné dans le Presse-papiers
    End Sub

    Private Sub PasteToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        'Utilisez My.Computer.Clipboard.GetText() ou My.Computer.Clipboard.GetData pour extraire les informations du Presse-papiers.
    End Sub


    Private Sub CascadeToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CascadeToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.Cascade)
    End Sub

    Private Sub TileVerticalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileVerticalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileVertical)
    End Sub

    Private Sub TileHorizontalToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TileHorizontalToolStripMenuItem.Click
        Me.LayoutMdi(MdiLayout.TileHorizontal)
    End Sub

    Private Sub ArrangeIconsToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs)
        Me.LayoutMdi(MdiLayout.ArrangeIcons)
    End Sub

    Private Sub CloseAllToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles CloseAllToolStripMenuItem.Click
        ' Fermez tous les formulaires enfants du parent.
        For Each ChildForm As Form In Me.MdiChildren
            ChildForm.Close()
        Next
    End Sub

    Private m_ChildFormNumber As Integer

    Private Sub Accueil_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        cn = New CnData()
        c = cn.getCn
        Dim ChildForm As New Login()
        ChildForm.ShowDialog(Me)
        If String.IsNullOrEmpty(userSite) Then Me.Close()
        cn.Open()
        Me.Text = Me.Text & " - " & user
        cmd = New SqlCommand("SELECT * FROM Profils WHERE Profil = '" & profil & "'", cn.getCn)
        dtr = cmd.ExecuteReader

        While dtr.Read()
            For Each m As ToolStripMenuItem In Me.MenuStrip.Items
                If m.Name = dtr("Menu").ToString & "ToolStripMenuItem" Then m.Visible = True
            Next
        End While
        dtr.Close()
        cn.Close()

    End Sub

    Private Sub con_StateChange(ByVal Sender As Object, ByVal E As StateChangeEventArgs) Handles c.StateChange
        If c.State = 1 Then
            ToolStripStatusLabel.Text = "Connecté"
        Else
            ToolStripStatusLabel.Text = "Déconnecté"
        End If
    End Sub

    Private Sub EtiquettesToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles EtiquettesToolStripMenuItem.Click
        For Each f As Form In Me.MdiChildren
            If f.Name = "Etiquettes" Then
                f.Activate()
                Exit Sub
            End If
        Next
        Dim ChildForm As New Etiquettes(user, cn, userSite)
        ChildForm.MdiParent = Me
        ChildForm.Show()
    End Sub


    Private Sub CréerUnChargementToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CréerUnChargementToolStripMenuItem.Click
        For Each f As Form In Me.MdiChildren
            If f.Name = "Chargement" Then
                f.Activate()
                Exit Sub
            End If
        Next
        Dim ChildForm As New Chargement(user, cn, userSite)
        ChildForm.MdiParent = Me
        ChildForm.Show()
    End Sub

    Private Sub RéceptionnerUnChargementToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RéceptionnerUnChargementToolStripMenuItem.Click
        For Each f As Form In Me.MdiChildren
            If f.Name = "Dechargement" Then
                f.Activate()
                Exit Sub
            End If
        Next
        Dim ChildForm As New Dechargement(user, cn, userSite)
        ChildForm.MdiParent = Me
        ChildForm.Show()
    End Sub

    Private SuEb ChargementÀVenirToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ChargementÀVenirToolStripMenuItem.Click
        For ach f As Form In Me.MdiChildren
            If f.Name = "AVenir" Then
                f.Activate()
                Exit Sub
            End If
        Next
        Dim ChildForm As New AVenir(user, cn, userSite)
        ChildForm.MdiParent = Me
        ChildForm.Show()
    End Sub


    Private Sub ReprendreUnChargementToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReprendreUnChargementToolStripMenuItem.Click
        For Each f As Form In Me.MdiChildren
            If f.Name = "RepriseC" Then
                f.Activate()
                Exit Sub
            End If
        Next
        Dim ChildForm As New RepriseC(user, cn, userSite)
        ChildForm.MdiParent = Me
        ChildForm.Show()
    End Sub

    Private Sub ReprendreUneRéceptionToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReprendreUneRéceptionToolStripMenuItem.Click
        For Each f As Form In Me.MdiChildren
            If f.Name = "RepriseD" Then
                f.Activate()
                Exit Sub
            End If
        Next
        Dim ChildForm As New RepriseD(user, cn, userSite)
        ChildForm.MdiParent = Me
        ChildForm.Show()
    End Sub

    Private Sub ConsulterUnBLToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConsulterUnBLToolStripMenuItem.Click
        For Each f As Form In Me.MdiChildren
            If f.Name = "DuplicataBL" Then
                f.Activate()
                Exit Sub
            End If
        Next
        Dim ChildForm As New DuplicataBL(user, cn, userSite)
        ChildForm.MdiParent = Me
        ChildForm.Show()
    End Sub

    Private Sub ConsulterUnBRToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ConsulterUnBRToolStripMenuItem.Click
        For Each f As Form In Me.MdiChildren
            If f.Name = "DuplicataBR" Then
                f.Activate()
                Exit Sub
            End If
        Next
        Dim ChildForm As New DuplicataBR(user, cn, userSite)
        ChildForm.MdiParent = Me
        ChildForm.Show()
    End Sub


    Private Sub ImprimanteToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub UtilisateursToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles UtilisateursToolStripMenuItem.Click
        For Each f As Form In Me.MdiChildren
            If f.Name = "Utilisateurs" Then
                f.Activate()
                Exit Sub
            End If
        Next
        Dim ChildForm As New Utilisateurs(user, cn, userSite)
        ChildForm.MdiParent = Me
        ChildForm.Show()
    End Sub

    Private Sub CréerUneZoneDeRoulageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CréerUneZoneDeRoulageToolStripMenuItem.Click
        For Each f As Form In Me.MdiChildren
            If f.Name = "NewZR" Then
                f.Activate()
                Exit Sub
            End If
        Next
        Dim ChildForm As New NewZR(user, cn, userSite)
        ChildForm.MdiParent = Me
        ChildForm.Show()
    End Sub

    Private Sub TracerUnAgrèsNLPToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TracerUnAgrèsNLPToolStripMenuItem.Click
        For Each f As Form In Me.MdiChildren
            If f.Name = "RechercheLP" Then
                f.Activate()
                Exit Sub
            End If
        Next
        Dim ChildForm As New RechercheLP(user, cn, userSite)
        ChildForm.MdiParent = Me
        ChildForm.Show()
    End Sub

    Private Sub ModifierUneZoneDeRoulageToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ModifierUneZoneDeRoulageToolStripMenuItem.Click
        For Each f As Form In Me.MdiChildren
            If f.Name = "ChangeZR" Then
                f.Activate()
                Exit Sub
            End If
        Next
        Dim ChildForm As New ChangeZR(user, cn, userSite)
        ChildForm.MdiParent = Me
        ChildForm.Show()
    End Sub

    Private Sub VolumétrieToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VolumétrieToolStripMenuItem.Click
        For Each f As Form In Me.MdiChildren
            If f.Name = "Volumetrie" Then
                f.Activate()
                Exit Sub
            End If
        Next
        Me.Cursor = Cursors.WaitCursor
        Dim ChildForm As New Volumetrie()
        ChildForm.MdiParent = Me
        ChildForm.Show()
        'Me.Cursor = Cursors.Default
    End Sub

    Private Sub Accueil_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Me.Refresh()
    End Sub


    Private Sub TracerUnAgrèsNSpécifiqueToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TracerUnAgrèsNSpécifiqueToolStripMenuItem.Click
        For Each f As Form In Me.MdiChildren
            If f.Name = "RechercheSPE" Then
                f.Activate()
                Exit Sub
            End If
        Next
        Dim ChildForm As New RechercheSPE(user, cn, userSite)
        ChildForm.MdiParent = Me
        ChildForm.Show()
    End Sub

    Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
        Dim ChildForm As New Imprimantes()
        ChildForm.ShowDialog()
    End Sub
End Class
